package com.fsoft.tinhcd.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.persistence.oxm.annotations.XmlInverseReference;

@Entity
@Table(name = "REGIONS")
@XmlRootElement(name = "Region")
// if declate annotation in field, enable this Annotaion
// @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = { "regionId", "regionName", "countries" })
public class Region implements Serializable {
	private static final long serialVersionUID = 1L;
	private String regionId;
	private String regionName;
	List<Country> countries = new ArrayList<Country>();

	public Region() {
		super();
	}

	@Id
	@Column(name = "REGION_ID", unique = true, nullable = false)
	@XmlElement(name = "REGION_ID")
	@XmlID
	public String getRegionId() {
		return regionId;
	}

	public void setRegionId(String regionId) {
		this.regionId = regionId;
	}

	@Column(name = "REGION_NAME")
	@XmlElement(name = "REGION_NAME")
	public String getRegionName() {
		return regionName;
	}

	public void setRegionName(String regionName) {
		this.regionName = regionName;
	}

	@OneToMany(fetch = FetchType.EAGER, mappedBy = "region")
	@XmlInverseReference(mappedBy = "region")
	@XmlElement(name = "countries")
	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}
}
